/*
Copyright (c) 2020, Huawei Technologies Co., Ltd
 All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

* Description: 2D图表可视化插件数据组织类
*/
#ifndef CURVE_DATA_H
#define CURVE_DATA_H

#include <QPolygonF>
#include "custom/PlotData.h"

namespace chart_plugin {
class CurveData {
public:
    CurveData() = default;
    ~CurveData() = default;

    /*
     * 功能：添加topic PlotData
     * 输入参数：msg-custom::PlotData::ConstPtr类型的规控二维曲线topic数据
     * 输出参数：无
     * 返回值：true-成功，false-失败
     */
    bool Add(const custom::PlotData::ConstPtr &msg);

    /*
     * 功能：清除缓存的topic数据
     * 输入参数：无
     * 输出参数：无
     * 返回值：无
     */
    void Clear();

    /*
     * 功能：获取First Curve曲线数据
     * 输入参数：无
     * 输出参数：无
     * 返回值：QPolygonF类型的曲线数据
     */
    const QPolygonF &GetFirstCurvePolyonF() const;

    /*
     * 功能：获取Second Curve曲线数据
     * 输入参数：无
     * 输出参数：无
     * 返回值：QPolygonF类型的曲线数据
     */
    const QPolygonF &GetSecondCurvePolyonF() const;

    /*
     * 功能：获取平均方差数据
     * 输入参数：无
     * 输出参数：无
     * 返回值：QString格式的平均方差值
     */
    const QString &GetSquareDifference() const;

private:
    /*
     * 功能：设置曲线QPolygonF数据信息
     * 输入参数：pointVector-订阅得到的topic数据中的曲线的PlotPoint数据
     * 输出参数：qPolygonF-曲线的QPolygonF数据
     * 返回值：true-成功，false-失败
     */
    bool SetCurveData(const std::vector<custom::PlotPoint> &pointVector, QPolygonF &qPolygonF) const;

    /*
     * 功能：设置平均方差数据信息
     * 输入参数：meanSquareDiffValue-订阅得到的topic数据中的平均方差数据
     * 输出参数：无
     * 返回值：void
     */
    void SetMeanSquareDiffData(double meanSquareDiffValue);

private:
    QPolygonF firstCurvePolyonF {};
    QPolygonF secondCurvePolyonF {};
    QString squareDifference {};
};
} // namespace chart_plugin

#endif // CURVE_DATA_H
